import os,sys,platform,time
import wmi
import win32com
def systemVersion(c):
    #c = wmi.WMI()
    memTotel=0
    sysVer=''
    cpuVer=''
    cpuLoad=''
    for sys in c.Win32_OperatingSystem():
        sysVer='系统版本:'+sys.Caption+' '+sys.OSArchitecture+' Build:'+sys.BuildNumber
        #print('进程总数:'+str(sys.NumberOfProcesses))
    for s2 in c.Win32_Processor():
        cpuVer='CPU型号:'+str(s2.Name)+'   '+str(s2.NumberOfCores)+'核'
    for mem in c.Win32_PhysicalMemory():
        memTotel=memTotel+int(mem.Capacity)/1048576
    for cpu in c.Win32_Processor():
        cpuLoad='CPU负载:'+str(cpu.LoadPercentage)+'%'
    memSys='内存:'+str(memTotel)+'MB'
    sysTotel={cpuVer,memSys,sysVer,cpuLoad,}
    return sysTotel
def diskList(c):
    #c=wmi.WMI()
    tmplist = []
    for disk in c.Win32_DiskDrive():
        tmpdict = {}
        tmpdict["硬盘："] = disk.Caption
        #tmpdict["剩余容量:"]=disk.FreeSpace()
        if disk.Size == None:
            tmpdict["大小："] = None
        else:
            tmpdict["大小："] = str(int(disk.Size) / 1024 / 1024 / 1024) + '-GB'
        tmplist.append(tmpdict)
    return tmplist
def GetIPList():
    import socket
    hostname = socket.gethostname()
    ip = socket.gethostbyname(hostname)
    return ip
def mkTemp(str):
# NowTime = time.strftime('%a %b %d %H:%M:%S %Y')
    f = open( 'WindowsInfo.log', 'a')
    f.write(str+'\n')
    f.close()
def getProInfo(c):
    #c=wmi.WMI()
    proInfo=[]
    for process in c.Win32_Process():
        tmp={}
        #print(process.ProcessId, process.Name)
        tmp['PID:'+str(process.ProcessId)]='进程名：'+process.Name
        proInfo.append(tmp)
    return proInfo
if __name__ == '__main__':
    c = wmi.WMI()
    if os.path.exists('WindowsInfo.log'):
        os.remove('WindowsInfo.log')
    mkTemp('IP地址:' + GetIPList())
    sysVer=systemVersion(c)
    diskInfo=diskList(c)
    for i in sysVer :
        #print(i)
        mkTemp(i)
    for ii in diskInfo:
        #print(ii)
        mkTemp(str(ii))
    proInfo=getProInfo(c)
    for pro in proInfo:
        mkTemp(str(pro))